<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of addPatent
 *
 * @author Runner
 */
class addPatentInfo extends AddInformation{
    private $patent;
    private $queryStr;
    
    function __construct($patent=null) {
        $this->patent = $patent;
        $this->queryStr = sprintf('insert into Patent(name, responsible, submitDate, authorizeDate, state, auditingState)'.
                                        'values("%s", "%s", "%s", "%s", "%s", "%s")', 
                                        $this->patent->name, $this->patent->responsible,
                                        $this->patent->submitDate, $this->patent->authorizeDate,
                                        $this->patent->state, $this->patent->auditingState
                                    );
        
    }
    
    public function add($linkIdentify) {
        if($this->check()){
            if($this->addInfo($this->queryStr, $linkIdentify)){
                return true;
            }
            return false;
        }
    }
    
    /* 检查数据是否合格 */
    function check(){
        if($this->patent==NULL){
            return false;
        }
        /* 检查是否为空字符串 */
        foreach (AttributesName::$patent as $value) {
            if($this->patent->$value==""){
                return false;
            }
        }
        /* 检查是否符合字符串要求 */
        $timePattern = '/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/';       // 日期的正则表达式模式
        if( preg_match($timePattern, $this->patent->submitDate)==0 ){
            return false;
        }
        if( preg_match($timePattern, $this->patent->authorizeDate)==0 ){
            return false;
        }
        /* 比较日期 */
        if( strtotime($this->patent->submitDate)>strtotime($this->patent->authorizeDate) ){
            return false;
        }
        return true;
    }
}
